import {createStackNavigator} from 'react-navigation';

import {
    createStore,
    applyMiddleware,
    combineReducers
} from 'redux';

import {
    reduxifyNavigator,
    createNavigationReducer,
    createReactNavigationReduxMiddleware
} from 'react-navigation-redux-helpers';

import {
    Provider,
    connect
} from 'react-redux';

import React from 'react';

import AppNavigator from './appView';

const navReducer = createNavigationReducer(AppNavigator);

const appReducer = combineReducers({
    nav: navReducer,
});

const middleware = createReactNavigationReduxMiddleware(
    'root',
    state => state.nav,
);

const App = reduxifyNavigator(AppNavigator, 'root');
const mapStateToProps = (state) => ({
    state: state.nav
});

const AppWithNavigationState = connect(mapStateToProps)(App);

const store = createStore(
    appReducer,
    applyMiddleware(middleware)
);


class Root extends React.Component {
    render() {
        return (
            <Provider store={store}>
            <AppWithNavigationState/>
            </Provider>
        )
    }
}
export default Root;

